package com.company.project.action;

import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.hibernate.classic.Session;

import com.company.project.bean.GType;
import com.company.project.bean.Goods;
import com.company.project.bean.ShopCar;
import com.company.project.bean.User;
import com.company.project.service.CarService;
import com.company.project.service.GTService;
import com.company.project.service.GoodsService;
import com.company.project.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

public class IndexAction extends ActionSupport{

	private static final long serialVersionUID = 1L;
	
	
	private GoodsService goodsService;
	private GTService gtService;
	private UserService userService;
	
	private List<?> topTypeList;
	private List<?> elist;
	private List<?> clist;
	private List<?> hlist;
	private List<?> flist;
	private List<?> plist;
	private int id;
	private Goods goods;
	private GType gtype;
	
	private String goodsname;
	private List<?> shopCarinGoods;
	private int buytotal;
	private CarService carService;
	private int gid;//从页面传递过来的

	
	
	@Override
	public String execute() throws Exception {
		topTypeList = gtService.findByPid(0);
		System.out.println(topTypeList.size());
		elist = goodsService.getByType(2); //电子产品
		clist = goodsService.getByType(1);  //服装配饰
		hlist = goodsService.getByType(7); //家居生活
		flist = goodsService.getByType(16); //美食美味
		plist = goodsService.getByType(17); //赏心植物
		System.out.println("execute......................");
		return SUCCESS;
	}
	
	public String addcar(){
		ShopCar sc = new ShopCar();
		/*user=userService.findCurrentUser();*/
		User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
		/*user.setId(1);*/
		sc.setUser(user);
		Goods goods = new Goods();
		System.out.println(gid);
		goods.setId(gid);
		
//		Set<Goods> goodsList = new HashSet<Goods>();
//		goodsList.add(goods);
		sc.setGoods(goods);
		sc.setGname(goodsname);
		sc.setBuytime(new Date());
		sc.setBuytotal(buytotal);
		carService.addCar(sc);
		return SUCCESS;
	}
	
	public String showcar() {
		//User sessionUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
		//int uid = sessionUser.getId();
		User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
		shopCarinGoods = carService.getByUid(user.getId());
		return SUCCESS;
	}
	
	
	public String showgoods(){
		 goods = goodsService.getById(id);
		return SUCCESS;
	}
	
	public Goods getGoods() {
		return goods;
	}

	public List<?> getTopTypeList() {
		return topTypeList;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public List<?> getClist() {
		return clist;
	}

	public int getId() {
		return id;
	}
	

	public GType getGtype() {
		return gtype;
	}

	public void setGtype(GType gtype) {
		this.gtype = gtype;
	}

	public void setId(int id) {
		this.id = id;
	}


	public void setClist(List<?> clist) {
		this.clist = clist;
	}




	public List<?> getHlist() {
		return hlist;
	}




	public void setHlist(List<?> hlist) {
		this.hlist = hlist;
	}




	public List<?> getFlist() {
		return flist;
	}




	public void setFlist(List<?> flist) {
		this.flist = flist;
	}




	public List<?> getPlist() {
		return plist;
	}




	public void setPlist(List<?> plist) {
		this.plist = plist;
	}




	

	public void setTopTypeList(List<?> topTypeList) {
		this.topTypeList = topTypeList;
	}

	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}

	public void setGtService(GTService gtService) {
		this.gtService = gtService;
	}

	public List<?> getElist() {
		return elist;
	}

	public void setElist(List<?> elist) {
		this.elist = elist;
	}

	public String getGoodsname() {
		return goodsname;
	}

	public void setGoodsname(String goodsname) {
		this.goodsname = goodsname;
	}

	public List<?> getShopCarinGoods() {
		return shopCarinGoods;
	}

	public void setShopCarinGoods(List<?> shopCarinGoods) {
		this.shopCarinGoods = shopCarinGoods;
	}

	public int getBuytotal() {
		return buytotal;
	}

	public void setBuytotal(int buytotal) {
		this.buytotal = buytotal;
	}

	public int getGid() {
		return gid;
	}

	public void setGid(int gid) {
		this.gid = gid;
	}

	public void setCarService(CarService carService) {
		this.carService = carService;
	}

	
	
	
}
